package com.giacom.abc.isabela.image;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Image {

	public void saveImage(InputStream image, String nome) throws Exception{
		
		try {
			
			BufferedInputStream in = new BufferedInputStream(image);

			byte buffer[]=new byte[20*1024];

			String imageDir = System.getProperty("abc.image.upload");
			
			FileOutputStream out = new FileOutputStream(imageDir + "/" + nome+".jpg");
			while(true) {
				  int readSize=in.read(buffer);
				  if(readSize==-1)
				    break;
				  out.write(buffer,0,readSize);
			}
			
			out.close();
			out.flush();
			
			System.out.println("fim");
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
		
	}
	
}
